﻿using Microsoft.Phone.Controls;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Windows8Accelerator.Core.Xaml.Helpers;

namespace Windows8Accelerator.Core.Xaml.Controls
{
    public class GroupItemControl : ListBox
    {
        public GroupItemControl()
        {
            //IsGroupingEnabled = false;
            //LayoutMode = LongListSelectorLayoutMode.List;
            this.SelectionChanged += GroupItemControl_SelectionChanged;
        }

        void GroupItemControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listViewBaseContentControl = this.GetParentOf<ListViewBaseContentControl>();
            if (e.AddedItems != null && e.AddedItems.Count > 0)
                listViewBaseContentControl.OnItemClick(e.AddedItems[0]);
            SelectedIndex = -1;
        }

        public DataTemplateSelector ItemTemplateSelector
        {
            get { return (DataTemplateSelector)GetValue(ItemTemplateSelectorProperty); }
            set { SetValue(ItemTemplateSelectorProperty, value); }
        }
        public static readonly DependencyProperty ItemTemplateSelectorProperty =
            DependencyProperty.Register("ItemTemplateSelector", typeof(DataTemplateSelector), typeof(GroupItemControl), new PropertyMetadata(null));

        public DataTemplate ItemTemplate1
        {
            get { return (DataTemplate)GetValue(ItemTemplate1Property); }
            set { SetValue(ItemTemplate1Property, value); }
        }
        public static readonly DependencyProperty ItemTemplate1Property =
            DependencyProperty.Register("ItemTemplate1", typeof(DataTemplate), typeof(GroupItemControl), new PropertyMetadata(null));        
    }
}
